package org.come.Jpanel;



import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.model.Eshop;
import org.come.until.CutButtonImage;
import org.come.until.DeviceEshopUntil;

import com.tool.btn.TaoBaoBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

public class ShopFlyJpanel extends JPanel {


    /** 7-17-HGC-start */
    // private TaoBaoBtn[] menuLable = new TaoBaoBtn[6];
    /**
     * 推荐recommendMenuBtn<br>
     * 上款newMenuBtn<br>
     */
    private TaoBaoBtn flyMenuBtn, flyMaterialMenuBtn;

    /** 7-17-HGC-end */
    private GoodsFlyMinJpanel[] goodsFlyMinJpanels = new GoodsFlyMinJpanel[9]; //
    private TaoBaoBtn btnhp,// 首页
            btnep,// 末页
            btnsyy,// 上一页
            btnxyy;// 下一页
    private JLabel labpage; // 放置当前页数和总页数
    private int nowPage = 1; // 当前页数
    private int maxPage = 1; // 最大页码
    /** "珍品"-6, "技能"-7, "神兽"-8, "仙器"-9, "配饰"-10, "积分"-11  "技能书"-12  "珍品" -13 ""-14*/
    private int shopType2 = 70;

    public ShopFlyJpanel() {
            this.setLayout(null);
            this.setPreferredSize(new Dimension(802, 538));
            this.setOpaque(false);
            this.setBackground(UIUtils.Color_BACK);
            labpage = new JLabel("1/1", SwingConstants.CENTER);
            labpage.setForeground(Color.white);
            labpage.setBounds(425, 435, 65, 20);
            labpage.setFont(UIUtils.TEXT_FONT1);
            this.add(labpage);
            // 首页
            btnhp = new TaoBaoBtn("inkImg/number/b8/shou.png", 1, "", 55, this);
            btnhp.setBounds(338, 435, 53, 20);
            this.add(btnhp);
            // 上一页
            btnsyy = new TaoBaoBtn("inkImg/number/b8/btn1-left.png", 1, "", 56, this);
            btnsyy.setBounds(401, 435, 19, 20);
            this.add(btnsyy);
            // 下一页
            btnxyy = new TaoBaoBtn("inkImg/number/b8/btn1-right.png", 1, "", 57, this);
            btnxyy.setBounds(500, 435, 19, 20);
            this.add(btnxyy);
            // 末页
            btnep = new TaoBaoBtn("inkImg/number/b8/wei.png", 1, "", 58, this);
            btnep.setBounds(520, 435, 53, 20);
            this.add(btnep);
            /** 7-17-HGC-start */
            // String[] menuStr = new String[] { "珍品", "技能", "神兽", "仙器", "配饰", "积分"
            // };
            // // 设置菜单按钮监听
            // for (int i = 0; i < menuStr.length; i++) {
            // menuLable[i] = new TaoBaoBtn("skin/8100226/button/3.png", 1, menuStr[i], i
            // + 10, this);
            // menuLable[i].setBounds(54 + i * 77, 14, 63, 26);
            // this.add(menuLable[i]);
            // }
            // try {
            // menuLable[0].setIcons(CutButtonImage.cuts("skin/8100226/button/4.png"));
            // } catch (Exception e) {
            // e.printStackTrace();
            // }
             getFlyMenuBtn();
             getFlyMaterialMenuBtn();
            /** 7-17-HGC-end */
            getShopGoodsView(this, DeviceEshopUntil.getShopingMenuFlyJpanel());

    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        	if (icon == null) {
                icon = CutButtonImage.getImage("inkImg/number/b8/topicon.png", 660, 30);
            }
            g.drawImage(icon.getImage(), 134, -1, 660, 29, this);

    }

    /** 初始化商品 */
    public void getShopGoodsView(ShopFlyJpanel shopFlyJpanel, List<Eshop> eshopList) {
    		maxPage = eshopList.size() % 9 == 0 ? eshopList.size() / 9 : eshopList.size() / 9 + 1;
            labpage.setText(nowPage + "/" + maxPage);
            for (int i = 9 * (nowPage - 1); i < 9 * nowPage; i++) {
                int row = i / 3;
                int rank = i % 3;
                if (i >= eshopList.size()) {
                    break;
                }
                goodsFlyMinJpanels[i] = new GoodsFlyMinJpanel(eshopList.get(i));
                goodsFlyMinJpanels[i].setBounds(145 + rank * 220, 60 + row * 120, 210, 110);//修改

                shopFlyJpanel.add(goodsFlyMinJpanels[i]);
            }

    }

    public void isShopGoods1(int shopType2) {

        this.shopType2 = shopType2;
        /** "飞行器"-70, "材料"-71*/
        switch (shopType2) {
        case 70:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuFlyJpanel());
            break;
        case 71:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuFlyMaterialJpanel());
            break;
        default:
            break;
        }
    }

    /** 更换展示的商品 */
    public void changeShopGoodsView(List<Eshop> eshopList) {
        for (int i = 0; i < goodsFlyMinJpanels.length; i++) {
            if(goodsFlyMinJpanels[i] == null){
                continue;
            }
            goodsFlyMinJpanels[i].clearView();
        }
        maxPage = eshopList.size() % 9 == 0 ? eshopList.size() / 9 : eshopList.size() / 9 + 1;
        labpage.setText(nowPage + "/" + maxPage);
        int num = 0;
        for (int i = 9 * (nowPage - 1); i < 9 * nowPage; i++) {
            if (i >= eshopList.size()) {
                break;
            }
            goodsFlyMinJpanels[num].addEshopMessage(eshopList.get(i));
            num++;
        }
    }

    public int getShopType2() {
        return shopType2;
    }

    public void setShopType2(int shopType2) {
        this.shopType2 = shopType2;
    }

    public GoodsFlyMinJpanel[] getGoodsFlyMinJpanels() {
        return goodsFlyMinJpanels;
    }

    public void setGoodsFlyMinJpanels(GoodsFlyMinJpanel[] goodsFlyMinJpanels) { this.goodsFlyMinJpanels = goodsFlyMinJpanels;}

    public TaoBaoBtn getBtnhp() {
        return btnhp;
    }

    public void setBtnhp(TaoBaoBtn btnhp) {
        this.btnhp = btnhp;
    }

    public TaoBaoBtn getBtnep() {
        return btnep;
    }

    public void setBtnep(TaoBaoBtn btnep) {
        this.btnep = btnep;
    }

    public TaoBaoBtn getBtnsyy() {
        return btnsyy;
    }

    public void setBtnsyy(TaoBaoBtn btnsyy) {
        this.btnsyy = btnsyy;
    }

    public TaoBaoBtn getBtnxyy() {
        return btnxyy;
    }

    public void setBtnxyy(TaoBaoBtn btnxyy) {
        this.btnxyy = btnxyy;
    }

    public JLabel getLabpage() {
        return labpage;
    }

    public void setLabpage(JLabel labpage) {
        this.labpage = labpage;
    }

    public int getNowPage() {
        return nowPage;
    }

    public void setNowPage(int nowPage) {
        this.nowPage = nowPage;
    }

    public int getMaxPage() {
        return maxPage;
    }

    public void setMaxPage(int maxPage) {
        this.maxPage = maxPage;
    }

    public TaoBaoBtn getFlyMenuBtn() {
    		if (flyMenuBtn == null) {
                flyMenuBtn = new TaoBaoBtn("inkImg/number/b8/flymenu1.png", 1, "", 74, this);
                flyMenuBtn.setBounds(150, 0, 64, 28);
                this.add(flyMenuBtn);
            }

        return flyMenuBtn;
    }

    public void setFlyMenuBtn(TaoBaoBtn flyMenuBtn) {
        this.flyMenuBtn = flyMenuBtn;
    }

    public TaoBaoBtn getFlyMaterialMenuBtn() {
    		if (flyMaterialMenuBtn == null) {
                flyMaterialMenuBtn = new TaoBaoBtn("inkImg/number/b8/material.png", 1, "", 75, this);
                flyMaterialMenuBtn.setBounds(150 + 1 * 66, 0, 64, 28);
                this.add(flyMaterialMenuBtn);
            }

        return flyMaterialMenuBtn;
    }

    public void setFlyMaterialMenuBtn(TaoBaoBtn flyMaterialMenuBtn) {
        this.flyMaterialMenuBtn = flyMaterialMenuBtn;
    }

}
